
//
//  ActSettingViewController.m
//  ActSistant
//
//  Created by Loan Dinh on 2/22/13.
//

#import "ActSettingViewController.h"
#import "ActGlobal.h"
#import "NavigationView.h"
typedef enum ActSettingCell{
    ActSettingCell1 = 0,
    ActSettingCell2,
    ActSettingCell3,
    ActSettingCell4,
    ActSettingCell5
}ActSettingCell;

@class ActSettingCellWrapper;
@interface  ActSettingCellWrapper: NSObject
@property (nonatomic, retain) NSString *cellTitle;
@property (nonatomic, retain) NSString *cellSubttle;
@property (nonatomic, assign) ActSettingCell cellType;
@property (nonatomic, retain) UIImageView *cellImage;
@property (nonatomic, retain) UIView *cellAccessoryView;
-(id)initWithType:(int)type;
@end

@implementation  ActSettingCellWrapper
@synthesize cellSubttle, cellTitle,cellType,cellImage,cellAccessoryView;
- (id)initWithType:(int)type{
    self = [super init];
    if(self){
        cellType = type;
        cellImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
        cellAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 18)];
        switch (type) {
            case 0:
                cellType = ActSettingCell1;
                self.cellTitle = @"SAG Rules and Regulations";
                self.cellSubttle = @"Protect yourself";
                [self.cellImage setImage:[UIImage imageNamed:@"star_icon"]];
                break;
            case 1:
                cellType = ActSettingCell2;
                self.cellTitle = @"Pass Lock Settings";
                self.cellSubttle = @"Calculation";
                [self.cellImage setImage:[UIImage imageNamed:@"lock_icon"]];
                break;
            case 2:	
                cellType = ActSettingCell3;
                self.cellTitle = @"Feedback";
                self.cellSubttle = @"";
                [self.cellImage setImage:[UIImage imageNamed:@"feedback_icon"]];
                break;
            case 3:
                cellType = ActSettingCell4;
                self.cellTitle = @"Terms and Conditions";
                self.cellSubttle = @"";
                [self.cellImage setImage:[UIImage imageNamed:@"term_condition"]];
                break;
            case 4:
                cellType = ActSettingCell5;
                self.cellTitle = @"Log out";
                self.cellSubttle = @"";
                [self.cellImage setImage:[UIImage imageNamed:@"logout_icon"]];
                break;
                
            default:
                break;
        }
    }
    [cellAccessoryView addSubview:cellImage];
    return self;
}
- (void)dealloc{
    [cellImage release];
    [cellAccessoryView release];
    [super dealloc];
    
}
@end
#pragma mark - end of ActSettingCellWrapper
@class ActSettingViewController;
@interface ActSettingViewController ()
{
//    NSArray *_tableData;
}
@end

@implementation ActSettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        // Do any additional setup after loading the view from its nib.
        
    }
    return self;
}
- (void)initData{
    NSMutableArray *test =[NSMutableArray array];
    for(int i= 0; i < 5 ; i++){
        [test addObject:[[ActSettingCellWrapper alloc] initWithType:i]];
    }
    NSLog(@"Number of element: %d",test.count);
//    _tableData = test;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initData];
    
//    [self.navigationController.navigationBar setBackgroundImage:kBackgroundNavigationBar forBarMetrics:UIBarMetricsDefault];
//    UIButton *spaceButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 10,10)];
//    spaceButton.userInteractionEnabled = NO;
//    [spaceButton setBackgroundImage:nil forState:UIControlStateNormal];
//    [spaceButton setBackgroundColor:[UIColor clearColor]];
//    UIBarButtonItem *spaceBtn = [[UIBarButtonItem alloc] initWithCustomView:spaceButton];
//    [spaceButton release];
//    UIButton *listButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,24, 24)];
//    [listButton setImage:[UIImage imageNamed:@"setting_list_button"] forState:UIControlStateNormal];
//    UIBarButtonItem *listBtn = [[UIBarButtonItem alloc] initWithCustomView: listButton];
//    [listButton release];
//    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:spaceBtn,listBtn, nil];
//    [listBtn release];
//    [spaceBtn release];
//    
////    self.navigationController.navigationBarHidden = true;
//    
//    self.navigationItem.hidesBackButton = YES;
//    UIView *viewBackBtn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 32)];
//    UILabel *backButtonTitle = [[UILabel alloc] initWithFrame:CGRectMake(47, 0, 150, 32)];
//    [backButtonTitle setBackgroundColor:[UIColor clearColor]];
//    [backButtonTitle setFont:UIFontSystemBold(20)];
//    [backButtonTitle setTextColor:[UIColor whiteColor]];
//    [backButtonTitle setText:kAppname];
//    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(2,2, 50,32)];
//    [viewBackBtn addSubview:backButtonTitle];
//    [backButtonTitle release];
//    [backButton addTarget:self action:@selector(doBackbarButton:) forControlEvents:UIControlEventTouchUpInside];
//    [backButton setImage:[UIImage imageNamed:@"backbar_button"] forState:UIControlStateNormal];
//    [viewBackBtn addSubview:backButton];
//    [backButton release];
//    
//    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithCustomView:viewBackBtn];
//    [viewBackBtn release];
//    self.navigationItem.leftBarButtonItem = backBtn;
//    [backBtn release];
    
    [self.navigationView.btnBack addTarget:self action:@selector(doBackbarButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationView.btnRight1 release];
    self.navigationView.btnRight1 = nil;
    
//    NSLog(@"nav controller: %@", self.navigationController);
//    NSLog(@"tab controller: %@", self.tabBarController);
    
}
-(void)doBackbarButton:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)dealloc{
//    [_tableData release];
    [_tableView release];
    [_navigationView release];
    [super dealloc];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - TableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        //title text
        [cell.textLabel setTextColor:[UIColor darkGrayColor]];
        [cell.textLabel setFont:UIFontSystem(16)];
        [cell.detailTextLabel setFont:UIFontSystem(11)];
        [cell setBackgroundColor:[UIColor clearColor]];
        [cell setBackgroundView:nil];
    }
    ActSettingCellWrapper *cellData = [[ActSettingCellWrapper alloc] initWithType:indexPath.section];
    cell.textLabel.text =cellData.cellTitle;
    cell.detailTextLabel.text = cellData.cellSubttle;
    cell.accessoryView = cellData.cellAccessoryView;
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView = nil;
    [cellData release];
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (void)viewDidUnload {
    [self setNavigationView:nil];
    [super viewDidUnload];
}
@end
